﻿using System;

namespace Reactor.Messaging.ServiceBus.Internals
{
    /// <summary>
    /// Class to define the necessary elements to subscribe to a particular message topic.
    /// </summary>
    public class SubscriptionTask : TaskBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionTask"/> class.
        /// </summary>
        /// <param name="messagingChannel">The MessagingChannel.</param>
        public SubscriptionTask(IMessagingChannel messagingChannel)
        {
            MessagingChannel = messagingChannel;
        }

        /// <summary>
        /// Gets or sets the subscription topic on which to subscribe.
        /// </summary>
        /// <value>The subscription topic.</value>
        public override sealed IMessagingChannel MessagingChannel { get; set; }

        /// <summary>
        /// Validates this instance by ensuring the MessagingChannel is not null.
        /// </summary>
        public override void Validate()
        {
            if (MessagingChannel == null)
                throw new InvalidOperationException("Cannot subscribe to null MessagingChannel.");
        }
    }
}
